<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>MYSQL | Danyhug's Blog</title><meta name="author" content="Danyhug"><meta name="copyright" content="Danyhug"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="description" content="MYSQL&#x3D;&#x3D;基本操作&#x3D;&#x3D;登录mysql net start mysql mysql -h 主机地址 -P 端口 -u 用户名 -p 密码  退出mysql quit; \q quit  &#x3D;&#x3D;数据库操作&#x3D;&#x3D;设置字符集set names 字符集; 创建数据库create database 数据库名 [库选项];  库选项 字符集 charset 当前数据库下所有表存储数据默认指定的字符集 ~ cha">
<meta property="og:type" content="article">
<meta property="og:title" content="MYSQL">
<meta property="og:url" content="http://danyhug.gitee.io/blog/2021/04/23/MYSQL/index.html">
<meta property="og:site_name" content="Danyhug&#39;s Blog">
<meta property="og:description" content="MYSQL&#x3D;&#x3D;基本操作&#x3D;&#x3D;登录mysql net start mysql mysql -h 主机地址 -P 端口 -u 用户名 -p 密码  退出mysql quit; \q quit  &#x3D;&#x3D;数据库操作&#x3D;&#x3D;设置字符集set names 字符集; 创建数据库create database 数据库名 [库选项];  库选项 字符集 charset 当前数据库下所有表存储数据默认指定的字符集 ~ cha">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://danyhug.gitee.io/blog/img/bgimg/9.jpg">
<meta property="article:published_time" content="2021-04-23T12:22:02.000Z">
<meta property="article:modified_time" content="2021-04-25T05:45:13.930Z">
<meta property="article:author" content="Danyhug">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://danyhug.gitee.io/blog/img/bgimg/9.jpg"><link rel="shortcut icon" href="/blog/img/favicon.png"><link rel="canonical" href="http://danyhug.gitee.io/blog/2021/04/23/MYSQL/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>var GLOBAL_CONFIG = { 
  root: '/blog/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
};

var saveToLocal = {
  set: function setWithExpiry(key, value, ttl) {
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}

// https://stackoverflow.com/questions/16839698/jquery-getscript-alternative-in-native-javascript
const getScript = url => new Promise((resolve, reject) => {
  const script = document.createElement('script')
  script.src = url
  script.async = true
  script.onerror = reject
  script.onload = script.onreadystatechange = function() {
    const loadState = this.readyState
    if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
    script.onload = script.onreadystatechange = null
    resolve()
  }
  document.head.appendChild(script)
})</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-04-25 13:45:13'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(function () {  window.activateDarkMode = function () {
    document.documentElement.setAttribute('data-theme', 'dark')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
    }
  }
  window.activateLightMode = function () {
    document.documentElement.setAttribute('data-theme', 'light')
   if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
    }
  }
  const autoChangeMode = 'false'
  const t = saveToLocal.get('theme')
  if (autoChangeMode === '1') {
    const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
    const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
    const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
    const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
    if (t === undefined) {
      if (isLightMode) activateLightMode()
      else if (isDarkMode) activateDarkMode()
      else if (isNotSpecified || hasNoSupport) {
        const now = new Date()
        const hour = now.getHours()
        const isNight = hour <= 6 || hour >= 18
        isNight ? activateDarkMode() : activateLightMode()
      }
      window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
        if (saveToLocal.get('theme') === undefined) {
          e.matches ? activateDarkMode() : activateLightMode()
        }
      })
    } else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else if (autoChangeMode === '2') {
    const now = new Date()
    const hour = now.getHours()
    const isNight = hour <= 6 || hour >= 18
    if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
    else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else {
    if (t === 'dark') activateDarkMode()
    else if (t === 'light') activateLightMode()
  }const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
   if (asideStatus === 'hide') {
     document.documentElement.classList.add('hide-aside')
   } else {
     document.documentElement.classList.remove('hide-aside')
   }
}const fontSizeVal = saveToLocal.get('global-font-size')
if (fontSizeVal !== undefined) {
  document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
}})()</script><meta name="generator" content="Hexo 5.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="http://q1.qlogo.cn/g?b=qq&amp;nk=153669225&amp;s=100" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">33</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">18</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">5</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url(/blog/img/bgimg/9.jpg)"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blog/">Danyhug's Blog</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">MYSQL</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-04-23T12:22:02.000Z" title="发表于 2021-04-23 20:22:02">2021-04-23</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-04-25T05:45:13.930Z" title="更新于 2021-04-25 13:45:13">2021-04-25</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="MYSQL"><a href="#MYSQL" class="headerlink" title="MYSQL"></a>MYSQL</h1><h2 id="基本操作"><a href="#基本操作" class="headerlink" title="==基本操作=="></a>==基本操作==</h2><h3 id="登录mysql"><a href="#登录mysql" class="headerlink" title="登录mysql"></a>登录mysql</h3><ol>
<li>net start mysql</li>
<li>mysql -h 主机地址 -P 端口 -u 用户名 -p 密码</li>
</ol>
<h3 id="退出mysql"><a href="#退出mysql" class="headerlink" title="退出mysql"></a>退出mysql</h3><ul>
<li>quit;</li>
<li>\q</li>
<li>quit</li>
</ul>
<h2 id="数据库操作"><a href="#数据库操作" class="headerlink" title="==数据库操作=="></a>==数据库操作==</h2><h3 id="设置字符集"><a href="#设置字符集" class="headerlink" title="设置字符集"></a>设置字符集</h3><p>set names 字符集;</p>
<h3 id="创建数据库"><a href="#创建数据库" class="headerlink" title="创建数据库"></a>创建数据库</h3><p>create database 数据库名 [库选项];</p>
<ul>
<li>库选项<ul>
<li>字符集 charset 当前数据库下所有表存储数据默认指定的字符集<ul>
<li>~ charset 字符集名称</li>
</ul>
</li>
<li>校对集 collate</li>
</ul>
</li>
</ul>
<h3 id="显示数据库"><a href="#显示数据库" class="headerlink" title="显示数据库"></a>显示数据库</h3><ul>
<li>显示所有<ul>
<li>show databases;</li>
</ul>
</li>
<li>显示部分数据库<ul>
<li>show databases like ‘匹配模式’;<ul>
<li>_ 匹配当前位置单个字符</li>
<li>% 匹配指定位置多个字符 </li>
</ul>
</li>
</ul>
</li>
<li>显示数据库创建语句<ul>
<li>show create databases 数据库名;</li>
</ul>
</li>
</ul>
<h3 id="选择数据库"><a href="#选择数据库" class="headerlink" title="选择数据库"></a>选择数据库</h3><p>use 数据库名;</p>
<h3 id="修改数据库"><a href="#修改数据库" class="headerlink" title="修改数据库"></a>修改数据库</h3><ul>
<li>修改数据库字符集<ul>
<li>alter database 数据库名 charset 字符集;</li>
</ul>
</li>
</ul>
<h3 id="删除数据库"><a href="#删除数据库" class="headerlink" title="删除数据库"></a>删除数据库</h3><p>drop database 数据库名;</p>
<h2 id="表操作"><a href="#表操作" class="headerlink" title="==表操作=="></a>==表操作==</h2><h3 id="普通创建表"><a href="#普通创建表" class="headerlink" title="普通创建表"></a>普通创建表</h3><p>create table 表名(字段名 字段类型 [字段属性], …) [表选项]</p>
<ul>
<li>挂到某数据库<ul>
<li>use 数据库</li>
<li>表名改为数据库.表名</li>
</ul>
</li>
<li>表选项<ul>
<li>Engine 存储引擎</li>
<li>Charset 字符集 - 只对自己有效</li>
<li>Collate 校对集 - 同上</li>
</ul>
</li>
</ul>
<h3 id="复制表结构"><a href="#复制表结构" class="headerlink" title="复制表结构"></a>复制表结构</h3><p>create table 数据表名 like 数据库.数据表;</p>
<h3 id="显示所有表"><a href="#显示所有表" class="headerlink" title="显示所有表"></a>显示所有表</h3><p>show tables;</p>
<h3 id="显示表结构"><a href="#显示表结构" class="headerlink" title="显示表结构"></a>显示表结构</h3><ul>
<li>describe 表名;</li>
<li>desc 表名;</li>
<li>show column from 表名;</li>
</ul>
<h3 id="显示表创建语句"><a href="#显示表创建语句" class="headerlink" title="显示表创建语句"></a>显示表创建语句</h3><p>show create table 表名;</p>
<h3 id="设置表属性"><a href="#设置表属性" class="headerlink" title="设置表属性"></a>设置表属性</h3><p>alter table 表名 表选项 值</p>
<h3 id="修改表结构"><a href="#修改表结构" class="headerlink" title="修改表结构"></a>修改表结构</h3><ul>
<li>修改表名<ul>
<li>rename table 旧 to 新</li>
</ul>
</li>
<li>修改表选项<ul>
<li>alter table 表名 新值</li>
</ul>
</li>
<li>新增字段<ul>
<li>alter table 表名 add [column] 新字段名 列类型 [列属性] [位置 first / after 字段名]</li>
</ul>
</li>
<li>修改字段名<ul>
<li>alter table 表名 change 旧字段 新字段 字段类型 [列属性] [新位置]</li>
</ul>
</li>
<li>修改字段类型(属性)<ul>
<li>alter table 表名 modify 字段名 新类型 [新属性] [新位置]</li>
</ul>
</li>
<li>删除字段<ul>
<li>alter table 表名 drop 字段名</li>
</ul>
</li>
</ul>
<h2 id="数据的基本操作"><a href="#数据的基本操作" class="headerlink" title="==数据的基本操作=="></a>==数据的基本操作==</h2><h3 id="插入操作"><a href="#插入操作" class="headerlink" title="插入操作"></a>插入操作</h3><ul>
<li>insert into 表名[(字段列表)] values(对应字段列表)</li>
<li>向所有字段插入数据，必须一一对应<ul>
<li>insert into 表名 values(对应表结构)</li>
</ul>
</li>
<li>插入多数据<ul>
<li>insert into 表名 values(表结构), (表结构)…;</li>
</ul>
</li>
</ul>
<h3 id="查询操作"><a href="#查询操作" class="headerlink" title="查询操作"></a>查询操作</h3><ul>
<li>查询全部数据<ul>
<li>select * from 表名;</li>
</ul>
</li>
<li>查询部分数据<ul>
<li>select 字段列表 from 表名</li>
</ul>
</li>
<li>简单条件查询数据<ul>
<li>select 字段列表 * from 表名 where 字段名=值;</li>
</ul>
</li>
</ul>
<h3 id="删除操作"><a href="#删除操作" class="headerlink" title="删除操作"></a>删除操作</h3><p>delete from 表名 [where 条件];</p>
<h3 id="更新操作"><a href="#更新操作" class="headerlink" title="更新操作"></a>更新操作</h3><p>update 表名 set 字段名 = 新值 [where 条件]</p>
<h2 id="其他"><a href="#其他" class="headerlink" title="==其他=="></a>==其他==</h2><h3 id="主键"><a href="#主键" class="headerlink" title="主键"></a>主键</h3><ul>
<li>随表创建<ul>
<li>在要当主键的字段后写primary key</li>
<li>在最后primary key(表名)</li>
</ul>
</li>
<li>表后增加<ul>
<li>alter table 表名 add primary key(‘字段’);</li>
</ul>
</li>
<li>查看主键<ul>
<li>查看表结构</li>
<li>查看表的创建语句</li>
</ul>
</li>
<li>删除主键<ul>
<li>alter table 表名 drop primary key;</li>
</ul>
</li>
</ul>
<h3 id="主键约束"><a href="#主键约束" class="headerlink" title="主键约束"></a>主键约束</h3><ol>
<li>当前字段对应的数据不能为空</li>
<li>当前字段对应的数据不能重复</li>
</ol>
<h3 id="自动增长"><a href="#自动增长" class="headerlink" title="自动增长"></a>自动增长</h3><p>字段后增加属性auto_increment</p>
<h3 id="修改自动增长"><a href="#修改自动增长" class="headerlink" title="修改自动增长"></a>修改自动增长</h3><p>alter table 表名 auto_increment = 值;</p>
<h3 id="删除自增"><a href="#删除自增" class="headerlink" title="删除自增"></a>删除自增</h3><p>alter table 表名 modify 字段 字段类型;</p>
<h2 id="唯一键"><a href="#唯一键" class="headerlink" title="==唯一键=="></a>==唯一键==</h2><ul>
<li>unique key 保证字段中数据唯一</li>
<li>在一张表中可以有多个</li>
<li>允许字段数据为NULL</li>
</ul>
<h3 id="创建唯一键"><a href="#创建唯一键" class="headerlink" title="创建唯一键"></a>创建唯一键</h3><ul>
<li>在字段后加unique key</li>
<li>在所有字段后写unique key(字段列表)</li>
<li>创建表后增加<ul>
<li>alter table 表名 add unique key(字段列表)</li>
</ul>
</li>
</ul>
<h3 id="删除唯一键"><a href="#删除唯一键" class="headerlink" title="删除唯一键"></a>删除唯一键</h3><ul>
<li>alter table 表名 drop index 唯一键名字;</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">Danyhug</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://danyhug.gitee.io/blog/2021/04/23/MYSQL/">http://danyhug.gitee.io/blog/2021/04/23/MYSQL/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://danyhug.gitee.io/blog" target="_blank">Danyhug's Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="/blog/img/bgimg/9.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/2021/04/29/%E8%BD%AE%E6%92%AD%E5%9B%BE%E7%9A%84%E5%AE%9E%E7%8E%B0/"><img class="prev-cover" src="/blog/img/bgimg/1.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">轮播图的实现</div></div></a></div><div class="next-post pull-right"><a href="/blog/2021/03/17/CSS%E6%8A%80%E5%B7%A7/"><img class="next-cover" src="/blog/img/bgimg/4.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">CSS技巧</div></div></a></div></nav></div><div class="aside_content" id="aside_content"><div class="card-widget card-info"><div class="card-content"><div class="card-info-avatar is-center"><img class="avatar-img" src="http://q1.qlogo.cn/g?b=qq&amp;nk=153669225&amp;s=100" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">Danyhug</div><div class="author-info__description"></div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">33</div></a></div><div class="card-info-data-item is-center"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">18</div></a></div><div class="card-info-data-item is-center"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">5</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/danyhug"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/danyhug" target="_blank" title="Gitee"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:danyhug@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div></div><div class="card-widget card-announcement"><div class="card-content"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="card-content"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#MYSQL"><span class="toc-number">1.</span> <span class="toc-text">MYSQL</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C"><span class="toc-number">1.1.</span> <span class="toc-text">&#x3D;&#x3D;基本操作&#x3D;&#x3D;</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%99%BB%E5%BD%95mysql"><span class="toc-number">1.1.1.</span> <span class="toc-text">登录mysql</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%80%80%E5%87%BAmysql"><span class="toc-number">1.1.2.</span> <span class="toc-text">退出mysql</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E6%93%8D%E4%BD%9C"><span class="toc-number">1.2.</span> <span class="toc-text">&#x3D;&#x3D;数据库操作&#x3D;&#x3D;</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%BE%E7%BD%AE%E5%AD%97%E7%AC%A6%E9%9B%86"><span class="toc-number">1.2.1.</span> <span class="toc-text">设置字符集</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="toc-number">1.2.2.</span> <span class="toc-text">创建数据库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%98%BE%E7%A4%BA%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="toc-number">1.2.3.</span> <span class="toc-text">显示数据库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%80%89%E6%8B%A9%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="toc-number">1.2.4.</span> <span class="toc-text">选择数据库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="toc-number">1.2.5.</span> <span class="toc-text">修改数据库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="toc-number">1.2.6.</span> <span class="toc-text">删除数据库</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%A1%A8%E6%93%8D%E4%BD%9C"><span class="toc-number">1.3.</span> <span class="toc-text">&#x3D;&#x3D;表操作&#x3D;&#x3D;</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%99%AE%E9%80%9A%E5%88%9B%E5%BB%BA%E8%A1%A8"><span class="toc-number">1.3.1.</span> <span class="toc-text">普通创建表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%8D%E5%88%B6%E8%A1%A8%E7%BB%93%E6%9E%84"><span class="toc-number">1.3.2.</span> <span class="toc-text">复制表结构</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%98%BE%E7%A4%BA%E6%89%80%E6%9C%89%E8%A1%A8"><span class="toc-number">1.3.3.</span> <span class="toc-text">显示所有表</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%98%BE%E7%A4%BA%E8%A1%A8%E7%BB%93%E6%9E%84"><span class="toc-number">1.3.4.</span> <span class="toc-text">显示表结构</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%98%BE%E7%A4%BA%E8%A1%A8%E5%88%9B%E5%BB%BA%E8%AF%AD%E5%8F%A5"><span class="toc-number">1.3.5.</span> <span class="toc-text">显示表创建语句</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%BE%E7%BD%AE%E8%A1%A8%E5%B1%9E%E6%80%A7"><span class="toc-number">1.3.6.</span> <span class="toc-text">设置表属性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E8%A1%A8%E7%BB%93%E6%9E%84"><span class="toc-number">1.3.7.</span> <span class="toc-text">修改表结构</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C"><span class="toc-number">1.4.</span> <span class="toc-text">&#x3D;&#x3D;数据的基本操作&#x3D;&#x3D;</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8F%92%E5%85%A5%E6%93%8D%E4%BD%9C"><span class="toc-number">1.4.1.</span> <span class="toc-text">插入操作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E8%AF%A2%E6%93%8D%E4%BD%9C"><span class="toc-number">1.4.2.</span> <span class="toc-text">查询操作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E6%93%8D%E4%BD%9C"><span class="toc-number">1.4.3.</span> <span class="toc-text">删除操作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9B%B4%E6%96%B0%E6%93%8D%E4%BD%9C"><span class="toc-number">1.4.4.</span> <span class="toc-text">更新操作</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%85%B6%E4%BB%96"><span class="toc-number">1.5.</span> <span class="toc-text">&#x3D;&#x3D;其他&#x3D;&#x3D;</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%BB%E9%94%AE"><span class="toc-number">1.5.1.</span> <span class="toc-text">主键</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%BB%E9%94%AE%E7%BA%A6%E6%9D%9F"><span class="toc-number">1.5.2.</span> <span class="toc-text">主键约束</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%87%AA%E5%8A%A8%E5%A2%9E%E9%95%BF"><span class="toc-number">1.5.3.</span> <span class="toc-text">自动增长</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E8%87%AA%E5%8A%A8%E5%A2%9E%E9%95%BF"><span class="toc-number">1.5.4.</span> <span class="toc-text">修改自动增长</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E8%87%AA%E5%A2%9E"><span class="toc-number">1.5.5.</span> <span class="toc-text">删除自增</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%94%AF%E4%B8%80%E9%94%AE"><span class="toc-number">1.6.</span> <span class="toc-text">&#x3D;&#x3D;唯一键&#x3D;&#x3D;</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E5%94%AF%E4%B8%80%E9%94%AE"><span class="toc-number">1.6.1.</span> <span class="toc-text">创建唯一键</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E5%94%AF%E4%B8%80%E9%94%AE"><span class="toc-number">1.6.2.</span> <span class="toc-text">删除唯一键</span></a></li></ol></li></ol></li></ol></div></div></div><div class="card-widget card-recent-post"><div class="card-content"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/05/09/jQuery%E7%9A%84%E4%B8%80%E4%BA%9B%E6%93%8D%E4%BD%9C/" title="jQuery的一些操作"><img src="/blog/img/bgimg/6.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="jQuery的一些操作"/></a><div class="content"><a class="title" href="/blog/2021/05/09/jQuery%E7%9A%84%E4%B8%80%E4%BA%9B%E6%93%8D%E4%BD%9C/" title="jQuery的一些操作">jQuery的一些操作</a><time datetime="2021-05-09T02:43:29.000Z" title="发表于 2021-05-09 10:43:29">2021-05-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/04/29/%E8%BD%AE%E6%92%AD%E5%9B%BE%E7%9A%84%E5%AE%9E%E7%8E%B0/" title="轮播图的实现"><img src="/blog/img/bgimg/1.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="轮播图的实现"/></a><div class="content"><a class="title" href="/blog/2021/04/29/%E8%BD%AE%E6%92%AD%E5%9B%BE%E7%9A%84%E5%AE%9E%E7%8E%B0/" title="轮播图的实现">轮播图的实现</a><time datetime="2021-04-29T08:10:46.000Z" title="发表于 2021-04-29 16:10:46">2021-04-29</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/04/23/MYSQL/" title="MYSQL"><img src="/blog/img/bgimg/9.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="MYSQL"/></a><div class="content"><a class="title" href="/blog/2021/04/23/MYSQL/" title="MYSQL">MYSQL</a><time datetime="2021-04-23T12:22:02.000Z" title="发表于 2021-04-23 20:22:02">2021-04-23</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/03/17/CSS%E6%8A%80%E5%B7%A7/" title="CSS技巧"><img src="/blog/img/bgimg/4.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="CSS技巧"/></a><div class="content"><a class="title" href="/blog/2021/03/17/CSS%E6%8A%80%E5%B7%A7/" title="CSS技巧">CSS技巧</a><time datetime="2021-03-17T04:25:15.000Z" title="发表于 2021-03-17 12:25:15">2021-03-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/02/24/%E6%B6%85%E6%99%AEMISC01-%E5%9B%BE%E7%89%87%E9%9A%90%E5%86%99/" title="涅普MISC01-图片隐写"><img src="/blog/img/bgimg/1.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="涅普MISC01-图片隐写"/></a><div class="content"><a class="title" href="/blog/2021/02/24/%E6%B6%85%E6%99%AEMISC01-%E5%9B%BE%E7%89%87%E9%9A%90%E5%86%99/" title="涅普MISC01-图片隐写">涅普MISC01-图片隐写</a><time datetime="2021-02-24T03:29:38.000Z" title="发表于 2021-02-24 11:29:38">2021-02-24</time></div></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By Danyhug</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><div class="js-pjax"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script defer id="ribbon" src="http://danyhug.gitee.io/blog/js/canvas-ribbon.min.js" size="150" alpha="0.6" zindex="-1" mobile="true" data-click="true"></script></div></body></html>